import java.util.Random;


public class Players implements Token{
private Deeds[] deeds;
private String name;
private int token;
private int position;
private int previousPosition;
private int money;
private boolean isJail=false;
private int getOutOfJail;



public Players(Deeds[] deeds){
	this.deeds=deeds;
	position = 0;
	previousPosition=0;
	money = 1500;
	
}

public void setName(String x){
	name = x;
}

public String getName(){
	return name;
}

public int getMoney(){
	return money;
}

public void setJail(boolean bool){
	this.isJail=bool;
	this.setPosition(10, true);
	this.setPreviousPosition();
}

public boolean getIsJail(){
	return isJail;
}

public void setMoney(int x){
	this.money=money+x;
}

	public void setToken(int x){
    token = x;
}

	public int getToken(){
		return token;
	}
	
	public void setPosition2(int x){
		this.position=x;
	}
	
	public void setPosition(int x, boolean jail){
		if(this.isJail==false){
		if(jail==false){
		this.position = this.position+x;
		if(position>39){
		this.setMoney(200);
		int y;
		y=this.position-40;
		this.position = y;
		}
		}
		}else{
			if(jail==true){
			this.position=x;
			System.out.println(this.position);
			}
		}
		
	}
	
	public int getPosition(){
		return position;
	}
	
	public void setPreviousPosition(){
		previousPosition = position;
		}

		public int getPrevPostition(){
		return previousPosition;
		}
		
	public boolean buyDeed(){
		boolean bool=true;
		String none = "NONE";
		int checker = 0;
		int j=0;
	for(int i=0; i<28 ; i++){
	if(deeds[i].getPosition()==this.position){
		j=i;
		i=28;
		checker=1;
	}
	if(checker==1){
	if(deeds[j].getOwner()!=none){
	
		bool= false;
		
	//walang mangyayare
	}else{
		checker=2;
	}
	}
	}
	if(checker==2){
	deeds[j].setOwner(this.name);
	this.money=this.money-deeds[j].getCost();
	bool= true;
	}
	return bool;
	}
	
	public void rent(){
	
	for(int i=0 ; i<28 ; i++){
	if(deeds[i].getPosition()==this.position){
	if(deeds[i].getOwner()!="NONE"&&deeds[i].getOwner()!=this.name){
	this.money=this.money-deeds[i].getRent();

	}
	}
	}
	}
	
	public void setGetOutOfJail(int x){
		if(x==0){
			getOutOfJail=x;
		}
		if(x==-1){
			getOutOfJail=getOutOfJail+x;
		}
		if(x==2){
		getOutOfJail=2;
		}
		
		if(getOutOfJail==0){
			this.setJail(false);
		}
		
		System.out.println(this.getOutOfJail);
	}
	public void sell(int x){
		int sell =deeds[x].getCost()/2;
		this.money = this.money+sell;
		deeds[x].setOwner(null);
	}

}


